package com.anket.poll.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.anket.poll.dao.PollDao;
import com.anket.poll.model.Poll;
import com.hibernate.util.HibernateUtil;

public class PollDaoImpl implements PollDao {

	
	public List<Poll> getAllPolls() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Query query = session.createQuery("from Poll");
		List<Poll> list = query.list();
		return list;
	}

	
	public List<Poll> getAllPollsWithOptionLimit(Integer limit) {
		List<Poll> newList = new ArrayList<Poll>();
		int m = 0;
		for (Poll poll : getAllPolls()) {
			m++;
			if (m < limit)
				newList.add(poll);
			else
				return newList;
		}
		return newList;
	}

}
